package com.controller;

import com.bean.GeLi;
import com.bean.LiuDeHua;
import com.bean.MoAttack;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class TestController {

    @RequestMapping("/ioc")
    public String ioc() {
        ApplicationContext context =
                new ClassPathXmlApplicationContext("classpath*:beans.xml");

        LiuDeHua geLi = (LiuDeHua) context.getBean("geLi");
        geLi.responseAsk("哈哈哈哈");

        MoAttack moAttack = (MoAttack) context.getBean("moAttack");
        moAttack.cityGateAsk();
        return "响应成功请查看控制台输出";

    }

    @Resource
    GeLi liuDeHua;

    @RequestMapping("/ioc2")
    public String ioc2() {
        ApplicationContext context =
                new ClassPathXmlApplicationContext("classpath*:beans.xml");
        LiuDeHua geLi = (LiuDeHua) context.getBean("geLi");
        geLi.responseAsk("哈哈哈哈");
        liuDeHua.responseAsk("接口注入_哈哈哈哈哈");
        MoAttack moAttack = (MoAttack) context.getBean("moAttack");
        moAttack.cityGateAsk();

        //构造器注入
        MoAttack moAttack1 = (MoAttack) context.getBean("moAttack_construct");
        moAttack1.cityGateAsk();
        //命名空间注入
        MoAttack moAttack2 = (MoAttack) context.getBean("moAttack_p");
        moAttack2.cityGateAsk();

        System.out.println("------");
        return "响应成功请查看控制台输出";
    }
}
